﻿using Base.Api.Models;
using Base.Api.Service;
using Common.AspNetCore;
using Common.Infrastructure;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Base.Api.Controllers
{
    [Route("api/AuthData")]
    public class AuthDataController : ApiController
    {
        private readonly AuthDataService authDataService;

        public AuthDataController(IServiceProvider provider, AuthDataService auth)
             : base(provider)
        {
            this.authDataService = auth;
        }

        [HttpPost, Route("FullUpdateAuthMemberAuth")]
        public async Task<ApiActionResult<bool>> FullUpdateAuthMemberAuth([FromBody] AuthMemberAuthModel request)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                 await this.authDataService.FullUpdateAuthMemberAuthAsync(request);
                return true;
            });
        }

        [HttpPost, Route("FullUpdateAuthRoleAuth")]
        public async Task<ApiActionResult<bool>> FullUpdateAuthRoleAuth([FromBody] AuthRoleAuthModel request)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                await this.authDataService.FullUpdateAuthRoleAuthAsync(request);
                return true;
            });
        }

        [HttpPost, Route("FullUpdateAuthRoleGroupAuth")]
        public async Task<ApiActionResult<bool>> FullUpdateAuthRoleGroupAuth([FromBody] AuthRoleGroupAuthModel request)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                await this.authDataService.FullUpdateAuthRoleGroupAuthAsync(request);
                return true;
            });
        }

        [HttpPost, Route("GetAuthMemberAuth")]
        public async Task<ApiActionResult<AuthMemberAuthModel>> GetAuthMemberAuth([FromBody] ApiParam apiParam)
        {
            return await SafeExecuteAsync<AuthMemberAuthModel>(async (param) =>
            {
                return await this.authDataService.GetAuthMemberAuthAsync(apiParam.Keyword);
            });
        }

        [HttpPost, Route("GetAuthRoleAuth")]
        public async Task<ApiActionResult<AuthRoleAuthModel>> GetAuthRoleAuth([FromBody] ApiParam apiParam)
        {
            return await SafeExecuteAsync<AuthRoleAuthModel>(async (param) =>
            {
                return await this.authDataService.GetAuthRoleAuthAsync(apiParam);
            });
        }

        [HttpPost, Route("GetAuthRoleGroupAuth")]
        public async Task<ApiActionResult<AuthRoleGroupAuthModel>> GetAuthRoleGroupAuth([FromBody] ApiParam apiParam)
        {
            return await SafeExecuteAsync<AuthRoleGroupAuthModel>(async (param) =>
            {
                return await this.authDataService.GetAuthRoleGroupAuthAsync(apiParam.Keyword);
            });
        }

        [HttpPost, Route("GetAuthRoleMenuAuth")]
        public async Task<ApiActionResult<MemberAuthMenuModel>> GetAuthRoleMenuAuth([FromBody] ApiParam apiParam)
        {
            return await SafeExecuteAsync<MemberAuthMenuModel>(async (param) =>
            {
                return await this.authDataService.GetAuthRoleMenuAsync(apiParam);
            });
        }

        [HttpPost, Route("GetAuthRoleMember")]
        public async Task<ApiActionResult<AuthRoleAuthModel>> GetAuthRoleMember([FromBody] ApiParam apiParam)
        {
            return await SafeExecuteAsync<AuthRoleAuthModel>(async (param) =>
            {
                return await this.authDataService.GetAuthRoleMember(apiParam);
            });
        }
    }
}
